package com.example.elasticsearch.data;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Document(indexName = "my-test-index") // 修改索引名称为表示测试的索引
@Data
@NoArgsConstructor
@AllArgsConstructor
public class MyDocument {

    @Id
    private String id;

    // 文本字段，适合全文检索
    @Field(type = FieldType.Text)
    private String textField;

    // 关键字字段，适合精确匹配
    @Field(type = FieldType.Keyword)
    private String keywordField;

    // 整数类型字段
    @Field(type = FieldType.Integer)
    private Integer integerField;

    // 长整型字段
    @Field(type = FieldType.Long)
    private Long longField;

    // 浮点型字段
    @Field(type = FieldType.Float)
    private Float floatField;

    // 双精度浮点型字段
    @Field(type = FieldType.Double)
    private Double doubleField;

    // 布尔类型字段
    @Field(type = FieldType.Boolean)
    private Boolean booleanField;

    // 日期字段，存储日期时间
    @Field(type = FieldType.Date)
    private LocalDate dateField;

    // 对象字段，嵌套文档
    @Field(type = FieldType.Object)
    private Map<String, Object> objectField;

    // 嵌套类型字段，支持复杂对象查询
    @Field(type = FieldType.Nested)
    private List<Map<String, Object>> nestedField;

    // 地理位置字段，存储地理坐标
    @Field
    private GeoPoint geoPointField;

    // IP 地址字段
    @Field(type = FieldType.Ip)
    private String ipField;
}
